<?php
require_once('init.php');
if (!Auth::isAdmin()) {
	header('Location: login_form.php');
	exit();
}
		// odbieramy dane z formularza 
			$id = $_POST['id'];
			$description = $_POST['description']; 
			$model = $_POST['model']; 
			$engine = $_POST['engine']; 
			$horsepower = $_POST['horsepower']; 
			$torque = $_POST['torque']; 
			$weight = $_POST['weight']; 

			$msg = "";
			if($id and $description and $model and $engine and $horsepower and $torque and $weight) 
			{      
				// uaktualniamy tabel� 
				$ins = @mysql_query("UPDATE driver SET id='$id', description='$description', model='$model', engine='$engine', horsepower='$horsepower', torque='$torque', weight='$weight' WHERE id=$id"); 
				 mysql_query($ins);
					if($ins) 
					$msg = "<br/>Yeah! You Did It! ,-)<br/>"; 
				else $msg = "Error - something goes wrong ' . mysql_error . '"; 
			} 
			//echo "<p></p>UPDATE driver SET id='$id', description='$description', model='$model', engine='$engine', horsepower='$horsepower', torque='$torque', weight='$weight' WHERE id=$id;";
		?>

<!DOCTYPE html>
<html>
<head>
<title>Silesia Racing Time Battle</title>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
 <meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>  
<script type="text/javascript" src="js/jquery.betterTooltip.js"></script>  
<script type="text/javascript" src="js/jquery-latest.js"></script> 
<script type="text/javascript" src="js/jquery.tablesorter.js"></script> 
</head>
<body>

    <div id="wrapper">
        <div id="headerwrap">
        <div id="header">
           <p align="right"> Silesia Racing Time Battle EVOLution</p>
        </div>
        </div>
		<div id="topwrap">
        <div id="top_home">		
           <h2>Time Battle - Edit Drivers</h2>
        </div>
        </div>
        <div id="leftcolumnwrap">
        <div id="leftcolumn">
            <?php include_once ('menu_left.php');?>
        </div>
        </div>
        <div id="contentwrap">
        <div id="content">
		<div>   
		<p></p>
		<?
		$id = (int)$_POST['id'];
		//	echo "$id";
		?>
			<table id="table-2">
	<thead>
		<th>Driver</th>
		<th>Model</th>
		<th>Engine</th>
		<th>Horsepower</th>
		<th>Torque</th>
		<th>Weight</th>
		<th>Update</th>
		<th>Delete</th>
	</thead>
	<tbody>
	
		<?php
			$result = mysql_query("SELECT id, description, model, engine, horsepower, torque, weight FROM driver"); 
			if (!$result) {
				die('Invalid query: ' . mysql_error());
			}
			while($row = mysql_fetch_array($result))
			{
			?>
			<form action="driver_edit.php" method="post">
			<?
				echo "<TR><input type=hidden name=id value='" . $row['id']  . "'> "; 
				$id = (int)$_POST['id']; 
				echo "<TD><input type=text name=description value='" . $row['description']  . "'></TD>";	   
				echo "<TD><input type=text name=model value='" . $row['model']  . "'> </TD>";  
				echo "<TD><input type=text name=engine value='" . $row['engine']  . "'></TD>";  
				echo "<TD><input type=text name=horsepower value='" . $row['horsepower']  . "' >Hp</TD>";  
				echo "<TD><input type=text name=torque value= '" . $row['torque']  . "' >Nm</TD>";  
				echo "<TD><input type=text name=weight value= '" . $row['weight']  . "' >Kg</TD>"; 
				echo "<TD><input type=submit value=Update></TD></form>";
				echo "<TD><a href=\"driver_delete.php?id=" . $row['id']  . "\"><img src=images/tooltip/Critical.png height=15 /></a></TD>";
				
			}
			
			  echo "</TR>"	;
		?> 
	</tbody>
</table>
		<? echo $msg; ?>

		</div>
        </div>
        </div>
        <div id="rightcolumnwrap">
        <div id="rightcolumn">
			<?php include_once ('right_column.php');?>
			<p></p>
        </div>
        </div>
        <div id="footerwrap">
        <div id="footer">
            <p>Silesia Racing Time Battle</p>
        </div>
        </div>
    </div>
</body>
</html>
